const mongoose = require('mongoose');

const NoticeSchema = new mongoose.Schema(
   {
      type: {
         type: String,
         enum: [
            'SEND_INVITATION', // 发送邀请
            'RECEIVE_INVITATION', // 拿到邀请                *需包含两者信息，获取通知时要排除sender角度, sender用的是SEND_INVITATION
            'INFORMED_ACCEPT_INVITATION', // 被告知接受邀请   *需包含两者信息，获取通知时要排除sender角度, sender用的是ACCEPT_INVITATION
            'INFORMED_REJECT_INVITATION', // 被告知拒绝邀请   *需包含两者信息，获取通知时要排除sender角度, sender用的是REJECT_INVITATION
            'ACCEPT_INVITATION', // 接受邀请
            'REJECT_INVITATION', // 拒绝邀请
            'KICK_OUT_MEMBER', // 踢出成员
            'INFORMED_KICK_OUT_MEMBER', // 被告知踢出
            'JOIN_BY_INVITATION_CODE', // 通过邀请码加入
            'INFORMED_SOMEONE_JOIN_BY_INVITATION_CODE', // 被告知有人通过邀请码加入
         ],
         required: true,
      },
      group: {
         type: mongoose.Schema.Types.ObjectId,
         ref: 'Group'
      },
      // 针对于发送者
      receivers: {
         type: [mongoose.Schema.Types.ObjectId],
         ref: 'User',
      },
      // 针对与接收者
      receiver: {
         type: mongoose.Schema.Types.ObjectId,
         ref: 'User',
      },
      sender: {
         type: mongoose.Schema.Types.ObjectId,
         ref: 'User',
      },
      status: {
         type: String,
         enum: ['read', 'unread'],
         default: 'unread',
      },
   },
   {
      timestamps: true,
   }
);

module.exports = mongoose.model('Notice', NoticeSchema);
